/*
 * @Author: Vorga
 * @LastEditors: Vorga
 */
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#include "queue.h"

 //创建
QueueArray* create_qa(size_t cal)
{
    QueueArray* qa = malloc(sizeof(QueueArray));
    qa->arr = malloc(sizeof(void*) * (cal + 1));
    qa->cal = cal + 1;
    qa->rear = 0;
    qa->front = 0;
    return qa;
}
//销毁
void destory_qa(QueueArray* qa)
{
    free(qa->arr);
    free(qa);
}
//入队
void push_qa(QueueArray* qa, void* ptr)
{
    //if (full_qa(qa)) return false;
    qa->arr[qa->rear] = ptr;
    qa->rear = (qa->rear + 1) % qa->cal;
    //return true;
}
//出队
void pop_qa(QueueArray* qa)
{
    //if (empty_qa(qa)) return false;
    qa->front = (qa->front + 1) % qa->cal;
    //return true;
}
//队头
void* front_qa(QueueArray* qa)
{
    return qa->arr[qa->front];
}
//队尾
void* rear_qa(QueueArray* qa)
{
    return qa->arr[(qa->rear - 1 + qa->cal) % qa->cal];
}
//队满
bool full_qa(QueueArray* qa)
{
    return (qa->rear + 1) % qa->cal == qa->front;
}
//队空
bool empty_qa(QueueArray* qa)
{
    return qa->rear == qa->front;
}
//队长
size_t size_qa(QueueArray* qa)
{
    return (qa->rear - qa->front + qa->cal) % qa->cal;
}